//
//  RootViewController.m
//  ForengnMenu
//
//  Created by @-@ on 16/1/12.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "RootViewController.h"

#import "BackTableViewCell.h"

#import "MyTabBarController.h"

@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>


@property (strong , nonatomic)UITabBarController * myTabbarController;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.myTableView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.0];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Icon_bg"]];    

    self.userHead = @[@"Icon_Learn_to_cook",@"Icon_My_recipe",@"Icon_My_collection",@"Icon_Topic_of_discussion",@"Icon_Life_circle"];
    
    self.userName = @[@"学做菜",@"我的菜谱",@"我的收藏",@"讨论话题",@"我的生活圈"];
    
    self.setLogo.image = [UIImage imageNamed:@"Icon_Set_up"];

    self.changeImageLogo.image = [UIImage imageNamed:@"Icon_Change_the_background_picture"];
    
    //加载整个工程的架构

    [self updataViewController];
}


//加载整个工程的架构
- (void)updataViewController{
    
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:18],
                                                           NSForegroundColorAttributeName : [UIColor blackColor]}];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    
    
    UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"LearnCook" bundle:[NSBundle mainBundle]];
    UINavigationController *navController1 = [storyboard1 instantiateInitialViewController];
    UIStoryboard *storyboard2 = [UIStoryboard storyboardWithName:@"MyMenu" bundle:nil];
    UINavigationController *navController2 = [storyboard2 instantiateInitialViewController];
    
    UIStoryboard *storyboard3 = [UIStoryboard storyboardWithName:@"MyCollection" bundle:nil];
    UINavigationController *navController3 = [storyboard3 instantiateInitialViewController];

    UIStoryboard *storyboard4 = [UIStoryboard storyboardWithName:@"MyDiscussion" bundle:nil];
    UINavigationController *navController4 = [storyboard4 instantiateInitialViewController];
    
    UIStoryboard *storyboard5 = [UIStoryboard storyboardWithName:@"MyLife" bundle:nil];
    UINavigationController *navController5 = [storyboard5 instantiateInitialViewController];
    
    
    MyTabBarController *tabBarController = [[MyTabBarController alloc] init];
    tabBarController.viewControllers = @[navController1, navController2, navController3, navController4,navController5];
    
    self.myTabbarController = tabBarController;
    
    //添加子控制器
    [self addChildViewController:tabBarController];
    
    //添加子视图
    [self.view addSubview:tabBarController.view];

    tabBarController.tabBar.hidden = YES;


}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else{
        return 5;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 104;
    }else{
        return 40;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 40;
    }else{
        return 0;
    }
}


//节与节之间透明
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView * v = [UIView new];
        v.frame = CGRectMake(0, 0, 320, 100);
        v.backgroundColor = [UIColor clearColor];
        return v;
        
    }else{
        return nil;
    }
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 36;
    }else{
        return 0;
    }
    
}


//节与节之间透明
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        UIView * v = [UIView new];
        v.frame = CGRectMake(0, 0, 320, 100);
        v.backgroundColor = [UIColor clearColor];
        return v;
        
    }else{
        return nil;
    }
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * identifier;
    if (indexPath.section == 0 && indexPath.row == 0) {
        identifier = @"cell1";
        
    }else{
        identifier = @"cell2";
    }
    
    
    BackTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.0];
    cell.userHeaderImageView.image = [UIImage imageNamed:@"headImage.jpg"];

    cell.userNameLabel.text = @"没什么特长";
    cell.userNameLabel.textColor = [UIColor whiteColor];
    cell.erWeiMaImageView.image = [UIImage imageNamed:@"Icon_Qr_code"];
    
    cell.userSexLabel.text = @"性别：女";
    cell.userSexLabel.textColor = [UIColor whiteColor];

    cell.adressLabel.text = @"湖南 长沙";
    cell.adressLabel.textColor = [UIColor whiteColor];
    cell.subTitle.text = @"“           嘴馋勤做菜，人丑多读书...“";
    cell.subTitle.textColor = [UIColor whiteColor];
    cell.contentLogo.image = [UIImage imageNamed:self.userHead[indexPath.row]];
    cell.contentClass.text = self.userName[indexPath.row];
    
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    return cell;
    
}

//点击时触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //取消选择状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        
        [self performSegueWithIdentifier:@"showMyInfo" sender:nil];
        
    }else{
        
        self.myTabbarController.selectedIndex = indexPath.row;
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"pushSlideslip" object:nil];
    }
}



- (IBAction)setAction:(id)sender {
    [self performSegueWithIdentifier:@"showseting" sender:nil];
    
//    self.myTabbarController.selectedIndex = 5;
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushSlideslip" object:nil];


}

- (IBAction)changeAction:(id)sender {

    [self performSegueWithIdentifier:@"showChangeBI" sender:nil];
    
}

@end
